﻿/*********************************************************************************************************
 * 												大盘数据js start											*
 ********************************************************************************************************/
/******************************************大盘数据查看详情 start *******************************************/
// 1 当期零售订单笔数
// 2 
function quertOrderXQ(query_type,mode_type){
	$("#daxq_sj").empty();
	$('.modal-loading').show();
	var type = $('input:radio[name="options"]:checked').val();
	var dateTime = null;
	if(type == 1){
		dateTime = $("#exampleInputEmail").val();
	}else if(type == 2){
		dateTime = $("#Week").val();
	}else if(type == 3){
		dateTime = $("#yearMonth").val();
	}
	if(mode_type == 1){
		dateTime = "2016-12-01~"+getNowFormatDate();
	}
	$.ajax({
    url: 'data_analysis_detail',
    data: {
    	"type":type,
    	"dateTime":dateTime,
    	"query_type":query_type,
    	"mode_type":mode_type
    },
    type: 'post',
    cache: false,
    dataType: 'json',
    success: function (data) {
		var datas = data.data;
		if(data.ret == 0){
			var innerHtml = "";
			$.each(datas.list, function (i, list) {
                if('orderPayNumber' == query_type){
                	innerHtml += '<li><a href="#"><i class="fa fa-circle text-navy"></i>' + 
        			list.storeName + ': ' + 
        			list.allOrderCount+ 
        			'（团课-'+list.teamOrderCount+
        			'；私教-'+list.ptOrderCount+
        			'；训练营-'+list.funCampOrderCount+
        			'；自助-'+list.selfOrderCount+
        			'；会员-'+list.vipOrderCount+'）'+ 
        			'</a></li>';
                }else{
                	innerHtml += '<li><a href="#"><i class="fa fa-circle text-navy"></i>' + 
        			list.storeName + ': ' + 
        			list.allOrderCount+ 
        			'（团课-'+list.teamOrderCount+
        			'；私教-'+list.ptOrderCount+
        			'；训练营-'+list.funCampOrderCount+
        			'；自助-'+list.selfOrderCount+'）'+ 
        			'</a></li>';
                }
				
                
            });
			innerHtml = innerHtml + '</br>'+getTitle(query_type);
			$("#daxq_sj").html(innerHtml);
		    $('.modal-loading').hide();
		    $('.bs-example-modal-lg-1').modal('toggle');
		}else{
			alert("查询失败！");
		}
    },
    error: function () {
        alert("页面数据加载失败！");
    }
	});	   
}
//	2 当期零售流水
function quertOrderAmt(query_type,mode_type){
	$("#daxq_sj").empty();
	$('.modal-loading').show();
	var type = $("#types").val();
	var dateTime = null;
	if(type == 1){
		dateTime = $("#exampleInputEmail").val();
	}else if(type == 2){
		dateTime = $("#Week").val();
	}else if(type == 3){
		dateTime = $("#yearMonth").val();
	}
	$.ajax({
    url: 'data_analysis_detail',
    data: {
    	"type":type,
    	"dateTime":dateTime,
    	"query_type":query_type,
    	"mode_type":mode_type
    },
    type: 'post',
    cache: false,
    dataType: 'json',
    success: function (data) {
		var datas = data.data;
		if(data.ret == 0){
			var innerHtml = "";
			$.each(datas.list, function (i, list) {
                innerHtml += '<li><a href="#"><i class="fa fa-circle text-navy"></i>' + 
	                			list.storeName + ': ' + 
	                			list.incomeAmt+ 
	                			'（团课-'+list.teamOrderAmt+
	                			'；私教-'+list.ptOrderAmt+
	                			'；训练营-'+list.funCampOrderAmt+
	                			'；自助-'+list.selfOrderAmt+'）'+ 
	                			'</a></li>';
            });
			innerHtml = innerHtml + '</br>'+getTitle(query_type);
			$("#daxq_sj").html(innerHtml);
		    $('.modal-loading').hide();
		    $('.bs-example-modal-lg-1').modal('toggle');
		}else{
			alert("查询失败！");
		}
    },
    error: function () {
        alert("页面数据加载失败！");
    }
	});	   
}

//5 当期新增会员
//6 当期新增会员流水
//7 当期会员实收
function quertOrderVip(query_type,mode_type){
	$("#daxq_sj").empty();
	$('.modal-loading').show();
	var type = $("#types").val();
	var dateTime = null;
	if(type == 1){
		dateTime = $("#exampleInputEmail").val();
	}else if(type == 2){
		dateTime = $("#Week").val();
	}else if(type == 3){
		dateTime = $("#yearMonth").val();
	}
	$.ajax({
    url: 'data_analysis_detail',
    data: {
    	"type":type,
    	"dateTime":dateTime,
    	"query_type":query_type,
    	"mode_type":mode_type
    },
    type: 'post',
    cache: false,
    dataType: 'json',
    success: function (data) {
		var datas = data.data;
		if(data.ret == 0){
			var innerHtml = "";
			if("vipWater" == query_type){
				
				$.each(datas.list, function (i, list) {
					debugger;
	                innerHtml += '<li><a href="#"><i class="fa fa-circle text-navy"></i>' + 
		                			list.typeName + ': ' + 
		                			list.amount+ 
		                			'</a></li>';
	            });
			}else{
				$.each(datas.list, function (i, list) {
	                innerHtml += '<li><a href="#"><i class="fa fa-circle text-navy"></i>' + 
		                			list.typeName + ': ' + 
		                			list.sumNum+ 
		                			'</a></li>';
	            });
			}
			innerHtml = innerHtml + '</br>'+getTitle(query_type);
			$("#daxq_sj").html(innerHtml);
		    $('.modal-loading').hide();
		    $('.bs-example-modal-lg-1').modal('toggle');
		}else{
			alert("查询失败！");
		}
    },
    error: function () {
        alert("页面数据加载失败！");
    }
	});	   
}

// 这里的方法只是弹出注释的没有请求后台的数据的
function quertOrderZhuShi(query_type){
	// 当期会员零售转化率
	if("vipConversionRate" == query_type){
		var  innerHtml = '';
		$("#dpxq").html('会员零售转化率');
		innerHtml += 	'<li>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>1、分子：分母里有≥1笔零售行为(购买团课、私教、训练营)的人数</a>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>2、分母：本统计周期内的在线会员数</a>'
						+'</li>';
		$("#daxq_sj").html(innerHtml);
	    $('.modal-loading').hide();
	    $('.bs-example-modal-lg-1').modal('toggle');
	    return false;
	}
	
	// 当期会员自助转化率
	if("vipSelfConversionRate" == query_type){
		$("#dpxq").html('会员自助转化率');
		var  innerHtml = '';
		innerHtml += 	'<li>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>1、分子：分母里有≥1笔自助订单的人数</a>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>2、分母：本统计周期内的在线会员数</a>'
						+'</li>';
		$("#daxq_sj").html(innerHtml);
	    $('.modal-loading').hide();
	    $('.bs-example-modal-lg-1').modal('toggle');
	    return false;
	}
	
	// 当期排课量
	if("courseCount" == query_type){
		$("#dpxq").html('排课量');
		var  innerHtml = '';
		innerHtml += 	'<li>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>1、本统计周期内状态为“已结束”的团课数量</a>'
						+'</li>';
		$("#daxq_sj").html(innerHtml);
	    $('.modal-loading').hide();
	    $('.bs-example-modal-lg-1').modal('toggle');
	    return false;
	}
	
	// 当期团课满课率
	if("teamFullClassRate" == query_type){
		var  innerHtml = '';
		$("#dpxq").html('团课满课率');
		innerHtml += 	'<li>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>1、分子：本统计周期内，状态为“已结束”的团课对应“已报人数+排队人数”之和</a>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>2、分母：本统计周期内，状态为“已结束”的团课对应“上限人数”之和</a>'
						+'</li>';
		$("#daxq_sj").html(innerHtml);
	    $('.modal-loading').hide();
	    $('.bs-example-modal-lg-1').modal('toggle');
	    return false;
	}
	
	// 用户平均购买次数
	if("averagePayCount" == query_type){
		$("#dpxq").html('用户平均购买次数');
		var  innerHtml = '';
		innerHtml += 	'<li>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>1、分子：本统计周期内，状态为“已完成”的订单总笔数（刨除会员自助订单）</a>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>2、分母：本统计周期内，有订单状态为“已完成”的用户数（刨除会员自助订单）</a>'
						+'</li>';
		$("#daxq_sj").html(innerHtml);
	    $('.modal-loading').hide();
	    $('.bs-example-modal-lg-1').modal('toggle');
	    return false;
	}
	
	// 会员续费率
	if("vipRenewalFeeRate" == query_type){
		$("#dpxq").html('会员续费率');
		var  innerHtml = '';
		innerHtml += 	'<li>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>1、分子：从所选择自然月1号至当前时间，有再次购买1笔会员订单的用户数</a>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>2、分母：选择的自然月内，有购买≥1笔会员订单的用户数</a>'
						+'</li>';
		$("#daxq_sj").html(innerHtml);
	    $('.modal-loading').hide();
	    $('.bs-example-modal-lg-1').modal('toggle');
	    return false;
	}
	
	//会员总实收
	if("vipAmt" == query_type){
		var  innerHtml = '';
		$("#dpxq").html('会员实收');
		innerHtml += 	'<li>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>1、会员实收 = （V1+V2+V3…） × 统计天数</a>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>2、V：统计周期内为在线会员的会员日均费用</a>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>3、会员日均费用：用户购买会员时的实付总金额 / 购买天数(含赠送)</a>'
						+'</li>';
		$("#daxq_sj").html(innerHtml);
	    $('.modal-loading').hide();
	    $('.bs-example-modal-lg-1').modal('toggle');
	    return false;
	}
	// 当期教练课时费
	if("coachAmt" == query_type){
		$("#dpxq").html('教练课时费');
		var  innerHtml = '';
		innerHtml += 	'<li>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>统计该教练在本统计周期内：“已完成的团课”+“已销课的私教课”+“已签到的檬营”</a>'
						+'</li>';
		$("#daxq_sj").html(innerHtml);
	    $('.modal-loading').hide();
	    $('.bs-example-modal-lg-1').modal('toggle');
	    return false;
	}
	
	// 当期流失会员数
	if("vipLost" == query_type){
		$("#dpxq").html('流失会员数');
		var  innerHtml = '';
		innerHtml += 	'<li>'
						+'<a href="#"><i class="fa fa-circle text-navy"></i>数据注释：在本统计周期内，用户身份由“会员”变为“非会员”，且没有续费的用户总数</a>'
						+'</li>';
		$("#daxq_sj").html(innerHtml);
	    $('.modal-loading').hide();
	    $('.bs-example-modal-lg-1').modal('toggle');
	    return false;
	}
	
}
// 
function quertOrderRate(query_type,mode_type){
	$("#daxq_sj").empty();
	$('.modal-loading').show();
	var type = $("#types").val();
	var dateTime = null;
	if(type == 1){
		dateTime = $("#exampleInputEmail").val();
	}else if(type == 2){
		dateTime = $("#Week").val();
	}else if(type == 3){
		dateTime = $("#yearMonth").val();
	}
	$.ajax({
	    url: 'data_analysis_detail',
	    data: {
	    	"type":type,
	    	"dateTime":dateTime,
	    	"query_type":query_type,
	    	"mode_type":mode_type
	    },
	    type: 'post',
	    cache: false,
	    dataType: 'json',
	    success: function (data) {
			var datas = data.data;
			if(data.ret == 0){
				var innerHtml = "";
				$.each(datas.list, function (i, list) {
	                innerHtml += '<li><a href="#"><i class="fa fa-circle text-navy"></i>' + 
		                			list 
		                			'</a></li>';
	            });
				innerHtml = innerHtml + '</br>'+getTitle(query_type);
				$("#daxq_sj").html(innerHtml);
			    $('.modal-loading').hide();
			    $('.bs-example-modal-lg-1').modal('toggle');
			}else{
				alert("查询失败！");
			}
	    },
	    error: function () {
	        alert("页面数据加载失败！");
	    }
	});
}

// 当期流失会员数
function quertVipLost(query_type,mode_type){
	$("#daxq_sj").empty();
	$('.modal-loading').show();
	var type = $("#types").val();
	var dateTime = null;
	if(type == 1){
		dateTime = $("#exampleInputEmail").val();
	}else if(type == 2){
		dateTime = $("#Week").val();
	}else if(type == 3){
		dateTime = $("#yearMonth").val();
	}
	$.ajax({
	    url: 'data_analysis_detail',
	    data: {
	    	"type":type,
	    	"dateTime":dateTime,
	    	"query_type":query_type,
	    	"mode_type":mode_type
	    },
	    type: 'post',
	    cache: false,
	    dataType: 'json',
	    success: function (data) {
			var datas = data.data;
			if(data.ret == 0){
				var innerHtml = "";
				$.each(datas.list, function (i, list) {
	                innerHtml += '<li><a href="#"><i class="fa fa-circle text-navy"></i>' + 
					                list.storeName + ': ' + 
				        			list.userNumber+ 
		                			'</a></li>';
	            });
				innerHtml = innerHtml + '</br>'+getTitle(query_type);
				$("#daxq_sj").html(innerHtml);
			    $('.modal-loading').hide();
			    $('.bs-example-modal-lg-1').modal('toggle');
			}else{
				alert("查询失败！");
			}
	    },
	    error: function () {
	        alert("页面数据加载失败！");
	    }
	});
}
/******************************************大盘数据查看详情 end  ********************************************/
/******************************************汇总类数据 start************************************************/

function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    return currentdate;
}
// 当前在线会员总数——查看详情
function quertUserStortCount(query_type,mode_type){
	
	$.ajax({
    url: 'data_analysis_detail',
    data: {
    	"type":'1',
    	"dateTime":'',
    	"query_type":query_type
    },
    type: 'post',
    cache: false,
    dataType: 'json',
    success: function (data) {
		var datas = data.data;
		if(data.ret == 0){
			var innerHtml = "";
			$.each(datas.list, function (i, list) {
                innerHtml += '<li><a href="#"><i class="fa fa-circle text-navy"></i>' + 
	                			list.storeName + ': ' + 
	                			list.userNumber+ 
	                			'</a></li>';
            });
			innerHtml = innerHtml +'</br>' + getTitle(query_type);
			$("#daxq_sj").html(innerHtml);
		    $('.modal-loading').hide();
		    $('.bs-example-modal-lg-1').modal('toggle');
		}else{
			alert("查询失败！");
		}
    },
    error: function () {
        alert("页面数据加载失败！");
    }
	});	   
}
/**
 * dataType 表示哪一类型的数据类型 有 大盘数据 和 汇总数据
 * type 表示查看的那个模块的详情
 */
function getTitle(type){
	var notes = '';
	// 1
	if(type == 'orderCount'){
		$("#dpxq").html('零售订单笔数');
		notes = '数据注释：所选统计周期内，汇总所有(或所选)门店的已付款零售订单笔数';
	}
	// 2
	else if(type == 'orderWater'){
		$("#dpxq").html('零售流水');
		notes = '数据注释：所选统计周期内，汇总各门店的已付款零售订单的流水金额';
	}
	// 3
	else if(type == 'orderRevenueAmt'){
		$("#dpxq").html('零售实收金额');
		notes = '数据注释：汇总所选统计周期内以下类型订单的实付金额'+
				'1、所有状态为“已完成”的团课、自助(仅统计普通用户)订单的实付金额</br>'+
				'2、所有已销课的私教课时费（私教订单实付总额/购买节数）</br>'+
				'3、所有已签到的檬营课时费（檬营订单实付总额/该檬营的节数）</br>';
	}
	// 4
	else if(type == 'orderPayNumber'){
		$("#dpxq").html('付费总人数');
		notes = '数据注释：所选统计周期内，汇总各门店有付款行为(零售+会员)的人数(去重)';
	}
	// 1
	else if(type == 'vipNum'){
		$("#dpxq").html('新增会员数');
		notes = '数据注释：所选统计周期内，新增的不同类型的会员数量';
	}
	// 2
	else if(type == 'vipWater'){
		$("#dpxq").html('会员流水');
		notes = '数据注释：所选统计周期内，汇总购买不同月份类型的会员订单的实付金额';
	}
	// 3
	else if(type == 'vipAmt'){
		$("#dpxq").html('会员实收');
		notes = '数据注释：1、会员实收 = （V1+V2+V3…） × 统计天数</br>'+
				'2、V：统计周期内为在线会员的会员日均费用</br>'+
				'3、会员日均费用：用户购买会员时的实付总金额 / 购买天数(含赠送)';
	}
	// 4 当期流失会员数
	else if(type == 'vipLost'){
		$("#dpxq").html('流失会员数');
		notes = '数据注释：在本统计周期内，用户身份由“会员”变为“非会员”，'+
				'且没有续费的用户总数';
	}
	// 1当期会员零售转化率
	else if(type == 'vipConversionRate'){
		$("#dpxq").html('会员零售转化率');
		notes = '数据注释：1、分子：分母里有≥1笔零售行为(购买团课、私教、训练营)的人数</br>'+
				'2、分母：本统计周期内的在线会员数';
	}
	// 2当期会员自助转化率
	else if(type == 'vipSelfConversionRate'){
		$("#dpxq").html('会员自助转化率');
		notes = '数据注释：1、分子：分母里有≥1笔自助订单的人数</br>'+
				'2、分母：本统计周期内的在线会员数';
	}
	// 3当期零售复购率
	else if(type == 'retailRechargeRate'){
		$("#dpxq").html('零售复购率');
		notes = '数据注释：1、分子：分母里有买过≥2笔的用户数</br>'+
				'2、分母：本统计周期内买过≥1笔零售订单的用户数';
	}
	// 4当期排课量
	else if(type == 'courseCount'){
		$("#dpxq").html('排课量');
		notes = '数据注释：本统计周期内状态为“已结束”的团课数量';
	}
	return notes;
}


/******************************************汇总类数据 end**************************************************/
/******************************************public method start *******************************************/
//获取最近三十天
function getNowThirtyDays() {
	debugger;
	var sort_datarange1 = $("#sort_datarange1").val();
	var date = new Date();
	var endDate = new Date();
	var startDate = new Date((+date)-30*24*3600*1000);// 获取三十天前
	var endDate=new Date();
	var endTime = endDate.getDate();
	var startTime = startDate.getDate();
   var seperator1 = "-";
   var seperator2 = ":";
   var seperator3 = "~";
   var month = date.getMonth() + 1;
   var monthEnd = endDate.getMonth() + 1;
   var monthStart = startDate.getMonth() + 1;
   var strDate = date.getDate();
   if (month >= 1 && month <= 9) {
       month = "0" + month;
       monthEnd = "0" + monthEnd;
       monthStart = "0" + monthStart;
   }
   if (endTime >= 0 && endTime <= 9) {
   	endTime = "0" + endDate.getDate();
   }
   if (startTime >= 0 && startTime <= 9) {
       startTime = "0" + startDate.getDate();
   }
   var currentdate = startDate.getFullYear() + seperator1 + monthStart + seperator1 + startTime + seperator3 +
   				  endDate.getFullYear() + seperator1 + monthEnd + seperator1 + endTime ;
   return currentdate;
}

//获取今天
function getNowToDays() {
   var date = new Date();
   var endDate = new Date();
   var startDate = new Date();// 获取三十天前
   var endDate=new Date();
   var endTime = endDate.getDate();
   var startTime = startDate.getDate();
   var seperator1 = "-";
   var seperator2 = ":";
   var seperator3 = "~";
   var month = date.getMonth() + 1;
   var monthEnd = endDate.getMonth() + 1;
   var monthStart = startDate.getMonth() + 1;
   var strDate = date.getDate();
   if (month >= 1 && month <= 9) {
       month = "0" + month;
       monthEnd = "0" + monthEnd;
       monthStart = "0" + monthStart;
   }
   if (endTime >= 0 && endTime <= 9) {
   	endTime = "0" + endDate.getDate();
   }
   if (startTime >= 0 && startTime <= 9) {
       startTime = "0" + startDate.getDate();
   }
   var currentdate = startDate.getFullYear() + seperator1 + monthStart + seperator1 + startTime + seperator3 +
   				  endDate.getFullYear() + seperator1 + monthEnd + seperator1 + endTime ;
   return currentdate;
}
//获取天 7天前
function getNowToSevenDays() {
	debugger;
	var date = new Date();
	var endDate = new Date();
	var startDate = new Date((+date)-7*24*3600*1000);// 获取三十天前
	var endDate=new Date();
	var endTime = endDate.getDate();
	var startTime = startDate.getDate();
    var seperator1 = "-";
    var seperator2 = ":";
    var seperator3 = "~";
    var month = date.getMonth() + 1;
    var monthEnd = endDate.getMonth() + 1;
    var monthStart = startDate.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
       month = "0" + month;
       monthEnd = "0" + monthEnd;
       monthStart = "0" + monthStart;
    }
    if (endTime >= 0 && endTime <= 9) {
    	endTime = "0" + endDate.getDate();
    }
    if (startTime >= 0 && startTime <= 9) {
    	startTime = "0" + startDate.getDate();
    }
    var currentdate = startDate.getFullYear() + seperator1 + monthStart + seperator1 + startTime + seperator3 +
   				  endDate.getFullYear() + seperator1 + monthEnd + seperator1 + endTime ;
   return currentdate;
}
//本月 
function getNowToMonthDays() {
	var date = new Date();
   var seperator1 = "-";
   var month = date.getMonth() + 1;
   if (month >= 1 && month <= 9) {
       month = "0" + month;
   }
   
   var currentdate = date.getFullYear() + seperator1 + month;
   return currentdate;
}
// 金额转换为大写  
var digitUppercase = function(n) {  
    var fraction = ['角', '分'];  
    var digit = [  
        '零', '壹', '贰', '叁', '肆',  
        '伍', '陆', '柒', '捌', '玖'  
    ];  
    var unit = [  
        ['元', '万', '亿'],  
        ['', '拾', '佰', '仟']  
    ];  
    var head = n < 0 ? '欠' : '';  
    n = Math.abs(n);  
    var s = '';  
    for (var i = 0; i < fraction.length; i++) {  
        s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');  
    }  
    s = s || '整';  
    n = Math.floor(n);  
    for (var i = 0; i < unit[0].length && n > 0; i++) {  
        var p = '';  
        for (var j = 0; j < unit[1].length && n > 0; j++) {  
            p = digit[n % 10] + unit[1][j] + p;  
            n = Math.floor(n / 10);  
        }  
        s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;  
    }  
    return head + s.replace(/(零.)*零元/, '元')  
        .replace(/(零.)+/g, '零')  
        .replace(/^整$/, '零元整');  
}; 

/******************************************public method end *******************************************/
/*********************************************************************************************************
 * 												大盘数据js end   											*
 ********************************************************************************************************/ 
        	


